extends Node2D

# 测试场景 - 演示玩家动态生成和场景切换

@onready var spawn_point = $SpawnPoint

func _ready():
	# 等待一帧确保场景完全加载
	await get_tree().process_frame
	
	# 设置默认生成点
	if PlayerManager != null and spawn_point != null:
		PlayerManager.set_default_spawn_position(spawn_point.position)
		
		# 只有在非传送情况下且没有玩家时才生成
		# 如果是通过传送门进入，SceneManager会处理玩家生成
		if SceneManager == null or SceneManager.target_portal_id.is_empty():
			if not PlayerManager.has_player():
				PlayerManager.spawn_player_in_current_scene()
	else:
		print("警告：PlayerManager或SpawnPoint不可用")

func _input(event):
	# 测试功能：按R键重新生成玩家
	if event.is_action_pressed("ui_home"):
		if PlayerManager != null:
			print("重新生成玩家...")
			PlayerManager.remove_current_player()
			await get_tree().process_frame
			PlayerManager.spawn_player_in_current_scene()
	
	# 测试功能：按End键移除玩家
	if event.is_action_pressed("ui_end"):
		if PlayerManager != null and PlayerManager.has_player():
			print("移除玩家...")
			PlayerManager.remove_current_player()
